/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "MUSIC_GROUP")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicGroup.findAll", query = "SELECT m FROM MusicGroup m"),
    @NamedQuery(name = "MusicGroup.findByIdMusicGroup", query = "SELECT m FROM MusicGroup m WHERE m.idMusicGroup = :idMusicGroup"),
    @NamedQuery(name = "MusicGroup.findByNameMusicGroup", query = "SELECT m FROM MusicGroup m WHERE m.nameMusicGroup = :nameMusicGroup"),
    @NamedQuery(name = "MusicGroup.findByFormationDate", query = "SELECT m FROM MusicGroup m WHERE m.formationDate = :formationDate")})
public class MusicGroup implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_MUSIC_GROUP")
    private Integer idMusicGroup;
    @Basic(optional = false)
    @Column(name = "NAME_MUSIC_GROUP")
    private String nameMusicGroup;
    @Basic(optional = false)
    @Column(name = "FORMATION_DATE")
    @Temporal(TemporalType.DATE)
    private Date formationDate;
    @ManyToMany(mappedBy = "musicGroupCollection")
    private Collection<Artist> artistCollection;
    @OneToMany(mappedBy = "idMusicGroup")
    private Collection<Album> albumCollection;

    public MusicGroup() {
    }

    public MusicGroup(Integer idMusicGroup) {
        this.idMusicGroup = idMusicGroup;
    }

    public MusicGroup(Integer idMusicGroup, String nameMusicGroup, Date formationDate) {
        this.idMusicGroup = idMusicGroup;
        this.nameMusicGroup = nameMusicGroup;
        this.formationDate = formationDate;
    }

    public Integer getIdMusicGroup() {
        return idMusicGroup;
    }

    public void setIdMusicGroup(Integer idMusicGroup) {
        Integer oldIdMusicGroup = this.idMusicGroup;
        this.idMusicGroup = idMusicGroup;
        changeSupport.firePropertyChange("idMusicGroup", oldIdMusicGroup, idMusicGroup);
    }

    public String getNameMusicGroup() {
        return nameMusicGroup;
    }

    public void setNameMusicGroup(String nameMusicGroup) {
        String oldNameMusicGroup = this.nameMusicGroup;
        this.nameMusicGroup = nameMusicGroup;
        changeSupport.firePropertyChange("nameMusicGroup", oldNameMusicGroup, nameMusicGroup);
    }

    public Date getFormationDate() {
        return formationDate;
    }

    public void setFormationDate(Date formationDate) {
        Date oldFormationDate = this.formationDate;
        this.formationDate = formationDate;
        changeSupport.firePropertyChange("formationDate", oldFormationDate, formationDate);
    }

    @XmlTransient
    public Collection<Artist> getArtistCollection() {
        return artistCollection;
    }

    public void setArtistCollection(Collection<Artist> artistCollection) {
        this.artistCollection = artistCollection;
    }

    @XmlTransient
    public Collection<Album> getAlbumCollection() {
        return albumCollection;
    }

    public void setAlbumCollection(Collection<Album> albumCollection) {
        this.albumCollection = albumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMusicGroup != null ? idMusicGroup.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicGroup)) {
            return false;
        }
        MusicGroup other = (MusicGroup) object;
        if ((this.idMusicGroup == null && other.idMusicGroup != null) || (this.idMusicGroup != null && !this.idMusicGroup.equals(other.idMusicGroup))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.MusicGroup[ idMusicGroup=" + idMusicGroup + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
